<template>
  <div>
    <div class="auditBtnDiv">
      <el-button size="small" type="primary" @click="clickBtn('doPass')">同意</el-button>
      <el-button size="small" type="primary" @click="clickBtn('doReject')">驳回</el-button>
      <el-button v-for="(item,i) in customBtnList" :key="item.buttonId" size="small" type="primary" @click="clickCustomBtn(item.buttonId, item)">{{item.buttonName}}</el-button>
    </div>
    <el-dialog title="审核意见" :visible.sync="desctDialog" width="400px" :close-on-click-modal="false" :destroy-on-close="true"
               v-if="desctDialog" top="30px" custom-class="myDialog" :append-to-body="true">
      <div>
        <div class="auditOpinionDiv">
          <el-input
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 4}"
            placeholder="请输入内容"
            v-model="auditOpinion">
          </el-input>
        </div>
        <div style="display: inline-block; width: 100%;text-align: right;">
          <el-button size="small" type="success" @click="doSave()">确定</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    name: 'workFlowAddSignerAuditButtonCom',
    data() {
      return {
        curUserId: this.$store.state.user.userid,
        curUserName: this.$store.state.user.name,
        curOrgId: this.$store.state.user.orgId,
        loading: false,
        auditBtnData: [],
        desctDialog: false,
        auditOpinion: '',
        optType: ''
      }
    },
    props: ['workitemInsId', 'customBtnList'],
    components: {
      //
    },
    created() {
      //
    },
    watch: {
      //
    },
    methods: {
      clickBtn(optType) {
        this.auditOpinion = ''
        this.optType = optType
        if (this.optType === 'doPass') {
          this.auditOpinion = '同意'
        }
        this.desctDialog = true
      },
      clickCustomBtn(btnId, btnInfo) {
        //
        this.$emit('auditAfter', btnInfo, {})
      },
      doSave() {
        let methodName = ''
        let btnInfo = {}
        if (this.optType === 'doPass') {
          btnInfo.buttonId = 'addSignerPass'
          btnInfo.buttonName = '加签通过'
          this.auditOpinion = '同意'
          methodName = 'WfBusiProcAddSignerPass'
        } else {
          btnInfo.buttonId = 'addSignerReject'
          btnInfo.buttonName = '加签驳回'
          methodName = 'WfBusiProcAddSignerReject'
        }

        this.desctDialog = false
        let args = {}
        args.busiUserId = this.curUserId
        args.busiUserName = this.curUserName
        args.workitemInsId = this.workitemInsId
        args.desc = this.auditOpinion

        this.$store.dispatch(methodName, args).then(res => {
          if (res && res.success) {
            this.$emit('auditAfter', btnInfo, args)
          } else {
            this.$message({
              type: 'danger',
              message: '操作异常!' + res.message
            })
          }
        }).catch((err) => {
          console.log(err)
        })
      }
    }
  }
</script>
<style scoped>
  .auditOpinionDiv {
    padding-bottom: 15px;
  }

</style>
